package com.design.paystyle.strategy;

import lombok.extern.slf4j.Slf4j;

/**
 * 策略工厂获取具体的策略实现
 *
 * @author by liuxin
 * @version 0.1
 * @date 2021-11-17 15:50
 */
@Slf4j
public class PayStrategyFactory {

    /**
     * 结合工厂来获取对应的策略实现
     *
     * @param strategyType
     * @return
     */
    public static PayStrategy getPayStrategy(String strategyType) {

        try {
            String className = PayEnumStrategy.valueOf(strategyType).getClassName();
            log.info("选择的支付类型：{}", strategyType);
            return (PayStrategy) Class.forName(className).newInstance();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

    }
}
